//
//  SSSWaitDiscopuntCell.m
//  SSSMerchant
//
//  Created by Darker on 2017/3/27.
//  Copyright © 2017年 xnxin. All rights reserved.
//

#import "SSSWaitDiscopuntCell.h"
#import "NSDateAddition.h"
#import "NSNumber+Addition.h"

@implementation SSSWaitDiscopuntCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        [self addSubViews];
    }
    return self;
}
- (void)addSubViews{
    
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    
    _selectedBtn = [UIButton new];
    [_selectedBtn setBackgroundImage:[UIImage imageNamed:@"icon_unchecked"] forState:UIControlStateNormal];
    [_selectedBtn addTarget:self action:@selector(isSelectButtonClick:) forControlEvents:UIControlEventTouchDown];
    [self.contentView addSubview:_selectedBtn];
    _selectedBtn.sd_layout
    .centerYEqualToView(self.contentView)
    .leftSpaceToView(self.contentView,WidthIos6CompeteWithCurrent(24))
    .widthIs(WidthIos6CompeteWithCurrent(19))
    .heightIs(HeigthIos6CompeteWithCurrent(19));
    //[selectedBtn sizeToFit];
    
    //时间
    _timeLabel = [UILabel new];
    _timeLabel.backgroundColor = [UIColor clearColor];
    _timeLabel.textAlignment = NSTextAlignmentCenter;
    _timeLabel.text = @"2017-08-35";
    _timeLabel.textColor = [UIColor colorWithHex:@"333333"];
    _timeLabel.font = [SSSFont systemFontOfSize:12];
    [self.contentView addSubview:_timeLabel];
    _timeLabel.sd_layout
    .leftSpaceToView(self.contentView,WidthIos6CompeteWithCurrent(73))
    .centerYEqualToView(self.contentView)
    .heightIs(HeigthIos6CompeteWithCurrent(20))
    .widthIs(WidthIos6CompeteWithCurrent(80));
    
    //金额
    _moneyLabel = [UILabel new];
    _moneyLabel.backgroundColor = [UIColor clearColor];
    _moneyLabel.text = @"￥3000";
    _moneyLabel.textAlignment = NSTextAlignmentCenter;
    _moneyLabel.textColor = [UIColor colorWithHex:@"333333"];
    _moneyLabel.font = [SSSFont systemFontOfSize:14];
    [self.contentView addSubview:_moneyLabel];
    _moneyLabel.sd_layout
    .leftSpaceToView(self.contentView,WidthIos6CompeteWithCurrent(166))
    .centerYEqualToView(self.contentView)
    .heightIs(HeigthIos6CompeteWithCurrent(20))
    .widthIs(WidthIos6CompeteWithCurrent(115));
    
    _discountNuLabel = [UILabel new];
    _discountNuLabel.backgroundColor = [UIColor clearColor];
    _discountNuLabel.text = @"￥3000";
    _discountNuLabel.textAlignment = NSTextAlignmentCenter;
    _discountNuLabel.textColor = [UIColor colorWithHex:@"333333"];
    _discountNuLabel.font = [SSSFont systemFontOfSize:14];
    [self.contentView addSubview:_discountNuLabel];
    _discountNuLabel.sd_layout
    .leftSpaceToView(self.contentView,WidthIos6CompeteWithCurrent(286))
    .centerYEqualToView(self.contentView)
    .heightIs(HeigthIos6CompeteWithCurrent(20))
    .widthIs(WidthIos6CompeteWithCurrent(75));
    
    //横线
    UIView *lineView = [UIView new];
    lineView.backgroundColor = [UIColor colorWithHex:@"E6E6E6"];
    [self.contentView addSubview:lineView];
    lineView.sd_layout
    .leftSpaceToView(self.contentView,WidthIos6CompeteWithCurrent(51))
    .rightSpaceToView(self.contentView,WidthIos6CompeteWithCurrent(16))
    .bottomSpaceToView(self.contentView,0)
    .heightIs(0.5);
}
/**
 * 对获得的数据进行处理
 */
- (void)customDataWithModel:(SSSWaitModel *)model{
    
    _model = model;
    if (model.createTime.length<=0) {
        
        self.timeLabel.text = @"";
        
    }else{
        
        NSString *subStr = [model.createTime substringWithRange:NSMakeRange(0,model.createTime.length - 3)];
        self.timeLabel.text = [NSString timeDateStrFromTimeStamp:subStr];
        
    }
    _moneyLabel.text = [NSString stringWithFormat:@"%@",model.money];
    _discountNuLabel.text = [NSString stringWithFormat:@"%@",model.rangli];
    
    
    if (model.isSelected) {
        _selectedBtn.selected = YES;
        [_selectedBtn setBackgroundImage:[UIImage imageNamed:@"icon_checked"] forState:UIControlStateSelected];
    }else{
        _selectedBtn.selected = NO;
        [_selectedBtn setBackgroundImage:[UIImage imageNamed:@"icon_unchecked"] forState:UIControlStateNormal];
    }
}
/**
 * cell上的选择
 *
 */

- (void)isSelectButtonClick:(UIButton *)button
{
    
    if (button.selected) {
        
        [_selectedBtn setBackgroundImage:[UIImage imageNamed:@"icon_checked"] forState:UIControlStateNormal];
        
    }else{
        
        [_selectedBtn setBackgroundImage:[UIImage imageNamed:@"icon_unchecked"] forState:UIControlStateSelected];
    }
    button.selected = !button.selected;
    _model.isSelected = !_model.isSelected;
    [self.delegate isSelect:self andModel:_model];
}

- (void)awakeFromNib {
    [super awakeFromNib];
    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    
    
    
}

@end
